<!--
 * @Description: 窗帘复杂加工
 * 
 * @Author: XiongYaoYuan<xiongyaoyuan>
 * @Date: 2023-04-25 16:11:18
 * @FilePath: /yuxiuproweb/src/views/process/machine/index.vue
-->
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="复杂加工名称" prop="complexMachiningName">
        <el-input
          v-model="queryParams.complexMachiningName"
          placeholder="请输入复杂加工名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类型" prop="type">
        <el-select
          v-model="queryParams.type"
          placeholder="请选择类型"
          style="width: 100%"
        >
          <el-option
            v-for="item in TYPES"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['md:machining:add']"
          >新增</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['md:machining:edit']"
          >修改</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['md:machining:remove']"
          >删除</el-button
        >
      </el-col>
      
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="machiningList"
      @selection-change="handleSelectionChange"
      :max-height="maxHeight"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        min-width="150"
        label="窗帘复杂加工名称"
        align="center"
        show-overflow-tooltip
        prop="complexMachiningName"
      />
      <el-table-column label="别名" align="center" prop="alias" />
      <el-table-column label="类型" align="center" prop="type">
        <template slot-scope="{ row }">
          {{ getTypeName(TYPES, row.type) }}
        </template>
      </el-table-column>
      <el-table-column
        label="描述"
        min-width="200"
        align="center"
        show-overflow-tooltip
        prop="isDescribe"
      />
      <el-table-column label="是否启用" align="center" prop="enableFlag">
        <template slot-scope="{ row: { enableFlag } }">
          {{ enableFlag === "Y" ? "是" : "否" }}
        </template>
      </el-table-column>
      <el-table-column label="价格模型" align="center" prop="chargeUnit">
        <template slot-scope="{ row }">
          {{ getTypeName(CHARGE_UNIT, row.chargeUnit) }}
        </template>
      </el-table-column>
      <el-table-column label="出厂价" align="center" prop="factoryPrice" />
      <el-table-column label="经销价" align="center" prop="wholesalePrice" />
      <el-table-column label="零售价" align="center" prop="retailPrice" />
      <!-- <el-table-column
        label="工序维护/操作"
        align="center"
        min-width="130"
        fixed="right"
        prop="process"
      >
        <template slot-scope="{ row }">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleProcess(row)"
            >编辑</el-button
          >
        </template>
      </el-table-column> -->
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        min-width="130"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['md:machining:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['md:machining:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改窗帘复杂加工对话框 -->
    <add-view
      v-if="open.show"
      :show.sync="open.show"
      v-bind="open"
      @update="getList()"
    ></add-view>
    <!-- 工序维护 -->
    <process-drawer
      v-if="process.show"
      :show.sync="process.show"
      v-bind="process"
    ></process-drawer>
  </div>
</template>

<script>
import { listMachining, delMachining } from "@/api/process/machine";
import AddView from "./mods/add.vue";
import { CHARGE_UNIT, TYPES } from "./configure";
import ProcessDrawer from "@/views/process/vm/mods/process/index.vue";
import commonMix from "@/utils/mixins/common";

export default {
  name: "Machining",
  mixins: [commonMix],
  components: {
    AddView,
    ProcessDrawer,
  },
  data() {
    return {
      CHARGE_UNIT,
      TYPES,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 窗帘复杂加工表格数据
      machiningList: [],
      // 是否显示弹出层
      open: {
        show: false,
        type: "add",
        data: null,
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        type: null,
        complexMachiningName: null,
        alias: null,
        isDescribe: null,
        enableFlag: null,
        chargeUnit: null,
        image: null,
        modelId: null,
        factoryPrice: null,
        wholesalePrice: null,
        retailPrice: null,
      },
      process: {
        show: false,
        productId: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询窗帘复杂加工列表 */
    getList() {
      this.loading = true;
      listMachining(this.queryParams).then((response) => {
        this.machiningList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.mdComplexMachiningId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.open = {
        show: true,
        type: "add",
        data: null,
      };
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.open = {
        show: true,
        type: "edit",
        data: {
          ...row,
        },
      };
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const mdComplexMachiningIds = row.mdComplexMachiningId || this.ids;
      this.$modal
        .confirm(
          '是否确认删除窗帘复杂加工编号为"' +
            mdComplexMachiningIds +
            '"的数据项？'
        )
        .then(function () {
          return delMachining(mdComplexMachiningIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 工序维护 */
    handleProcess({ mdComplexMachiningId }) {
      this.process = {
        show: true,
        productId: mdComplexMachiningId,
        type: "1",
      };
    },
    
  },
};
</script>
